
#ifndef PCCORE_H
#define PCCORE_H

#include <QObject>
#include <QQueue>
#include <QThread>
#include <QTimer>
#include <qreadwritelock.h>
#include "imagerecord.h"
#include "pcdual.h"
#include "pcfeature.h"
#include "quicktool.h"
#include "AutoPropertyHelper.h"

class
    PCcore : public QObject
{
    Q_OBJECT
public:
    static PCcore &getInstance();
    Q_INVOKABLE void loadModels(QString resNetModelPath = "/home/ASuser/master/models/PCresNect.rknn",
                                QString dualModelPath = "/home/ASuser/master/models/PCDual.rknn");

    Q_INVOKABLE void addTrainData();
    Q_INVOKABLE void clearTrainData();
    Q_INVOKABLE void startTrain();
    Q_INVOKABLE void enablePCcore();

    Q_INVOKABLE void setPCcoreROI(int x, int y , int wid, int hei);
    Q_INVOKABLE void resetPCcoreROI();

    cv::Mat cropImage(cv::Mat &image);


    Q_SIGNAL void respond(const bool isSuccess , const QString detail = QString());
    OR_QML_STATE_PROPERTY(QVariantMap, modelDetal, QVariantMap({}))
    OR_QML_STATE_PROPERTY(bool, isLoadModel, false);
    OR_QML_STATE_PROPERTY(bool, isenablePCcore, false);
    OR_QML_STATE_PROPERTY(float, detectionCore, 0);

     AUTO_CONFIG_PROPERTY(PCcore,"cvInspection", int, detectionThreshold)
    //GLOBAL_QML_STATE_PROPERTY(float, detectionThreshold , 1000)

    int process(ImageRecord &record, bool display = false);  //多线程
    PCFeature& getpcFutre();


    cv::Mat lastCvImage;
    cv::Rect roi;
signals:
    void dataCollectionComplete(int dataNum); //已采集到dataNum数据
    void trianStartSignal();
    void trianStartProcess(int process);
    void trianStartFinish();

private:
    QReadWriteLock lock;
    QReadWriteLock lastCvImageLock;

    PCcore(QObject *parent = nullptr);
    ~PCcore();
    PCcore& operator=(const PCcore& rhs) = delete;

    bool isTrain =false;
    PCFeature pcFutre;
    PCDual pcDual;


};


#endif // PCCORE_Hs
